package cn.iocoder.yudao.module.crm.service.task;

import cn.iocoder.yudao.module.crm.dal.dataobject.task.TaskOperationLogDO;
import cn.iocoder.yudao.module.crm.dal.mysql.task.TaskOperationLogMapper;
import cn.iocoder.yudao.module.crm.service.user.UserService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import java.util.List;

/**
 * CRM 任务单操作记录 Service 实现类
 *
 * @author 广州氪量
 */
@Service
@Validated
public class TaskOperationLogServiceImpl implements TaskOperationLogService {
    @Resource
    private TaskOperationLogMapper taskOperationLogMapper;
    @Resource
    private UserService userService;
    @Override
    public List<TaskOperationLogDO> getOperationByTaskId(Long id) {
        return taskOperationLogMapper.selectList(TaskOperationLogDO::getTaskId, id);
    }

    @Override
    public String getUsernameById(Long userId) {
        if(userId == 0){
            return "系统";
        }
        return userService.getUserNamesById(userId);
    }

    @Override
    public void createTaskOperationLog(Long taskId, Integer status,Long userId) {
        // status为0为系统创建
        taskOperationLogMapper.insert(TaskOperationLogDO.builder().build()
                .setTaskId(taskId).setOperationStatus(status).setUserId(userId));
    }
}